package nodes.command;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.ResourceBundle;
import java.util.Stack;
import model.Model;
import nodes.AbstractNode;


/**
 * Represents a command node where the arguments are stored as
 * a linked list in myNext
 */
public abstract class AbstractCommand
{
    protected static ResourceBundle resources = ResourceBundle.getBundle("resources.numOfCommandArgs");
    private static ResourceBundle numOfArgs_resources = ResourceBundle.getBundle("resources.numOfCommandArgs");
    protected static final String FALSE_VARIABLE_NAME = ":false";
    protected static final String TRUE_VARIABLE_NAME = ":true";
    
    
    public List<AbstractNode> setUpCommand(Queue<AbstractNode> outputQueue, String name)
    {
    
        List<AbstractNode> arguments = new ArrayList<AbstractNode>();
        
        int numOfArgsExpected = Integer.parseInt(numOfArgs_resources.getString(name));
     
        for(int argNum = 0; argNum < numOfArgsExpected; argNum++)
        {
        	
            arguments.add(outputQueue.poll().buildTree(outputQueue));
        }
        return arguments;
    }
    
    /**
     * Performs this command's action by utilizing myArugments
     */
    public abstract AbstractNode evaluate (List<AbstractNode> myArguments, Model model);

    
    /**
     * Returns the number of arguments that this command has
     */
    protected int getArgumentCount (AbstractNode arg)
    {
        int size = 0;
        while (arg != null)
        {
            size++;
            arg = arg.getNext();
        }
        return size;
    }
}
